package br.edu.ufcg.lsd.wbis.ui.client.ui.setup;

import br.edu.ufcg.lsd.wbis.ui.client.beans.UserInfo;
import br.edu.ufcg.lsd.wbis.ui.client.ui.management.PanelManager;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.gwtext.client.widgets.MessageBox;

/**
 * @author Renato Miceli
 */
public class CreateRootUserCallback implements AsyncCallback<UserInfo> {

	private final PanelManager panelManager;

	public CreateRootUserCallback(PanelManager panelManager) {
		this.panelManager = panelManager;
	}

	/**
	 * {@inheritDoc}
	 */
	public void onFailure(Throwable caught) {
		MessageBox.alert("Error", "Root user could not be created!");
	}

	/**
	 * {@inheritDoc}
	 */
	public void onSuccess(UserInfo result) {
		MessageBox.alert("Success", "Root user '" + result.getLogin() + "' created!");
		this.panelManager.switchToAdminPanel(result);
	}

}
